<template>
  <div class="wrapper">
    <div class="header">登录授权</div>
    <div class="img-wrap">
    </div>
    <div class="content">正在授权中...</div>
  </div>
</template>

<script>
import { isLogin } from '@/assets/js/isLogin'
export default {
  data () {
    return {
      sessid: ''
    }
  },
  methods: {
    postToken () {
      this.$api.login.loginSucc()
        .then(this.postTokenSucc)
        .catch((e) => {
          this.$errorTip()
        })
    },
    postTokenSucc (res) {
      const path = this.$localStorage.get('authUrl')
      res = res.data
      if (this.$api.CODE_OK === res.code && res.data) {
        const data = res.data
        const userInfo = {
          avatar: data.avatar,
          userName: data.nickname,
          vip: data.level,
          phone: data.phone
        }
        if (userInfo.phone === '') {
          this.$router.push({
            path: '/bindPhone'
          })
        } else {
          this.$localStorage.set('USER_INFO', JSON.stringify(userInfo))
          this.$router.replace(path)
          this.$tip(res.msg, 1000)
        }
      } else {
        this.$tip(res.msg, 1000)
        isLogin()
      }
    }
  },
  created () {
    this.postToken()
  }
}

</script>
<style lang='stylus' scoped>
@import '~stylus/variable.styl'
@import '~stylus/mixins.styl'

.wrapper
  width 100%
  height 100%

.header
  width 100%
  height 88px
  background $common_bgc
  box-shadow 0px 0px 0px 0px rgba(5, 5, 5, 0.12)
  display flex
  justify-content center
  align-items center
  font-size $back_fz
  color $common_fz_color
  font-weight 500

.img-wrap
  margin-bottom 100px

.content
  font-size $back_fz
  color $common_fz_color
  display flex
  width 100%
  justify-content center
</style>
